{% extends "base.html" %}

{% debug  %}
{% block head %}
  <script type="text/javascript">
  //<![CDATA[

  function newNote() {
    var form = document.getElementById("newnoteform");
    var dialog = document.getElementById("newnoteform_dialog");
    DialogBox.instance().show(dialog, function() {
      form["name"].focus();
    });
  }

  function selectLists(all) {
    var inputs = document.getElementsByTagName("input");
    for (var i = 0; i < inputs.length; i++) {
      var input = inputs[i];
      if (input.type == "checkbox" && input.className == "listcheckbox") {
        var id = input.id.substring(8);
        var row = document.getElementById("row" + id);
        input.checked = all;
        updateHighlight(input, row);
      }
    }
  }

  function updateHighlight(checkbox, row) {
    if (checkbox.checked) {
      row.style.backgroundColor = "#ffffcc";
    } else {
      row.style.backgroundColor = "white";
    }
  }

  //]]>
  </script>
{% endblock %}

{% block body %}
  <form action="/inboxaction.do" method="post">
    <div class="inbox">
      <input type="hidden" name="next" value="{{ request.uri|escape }}"/>
      <div class="menu">
        <span class="item"><a href="javascript:newNote()">New Note</a></span>
      </div>
      <div class="buttons top">
        <div class="left corner"></div>
        <div class="right corner"></div>
        <div class="info">
	  <span class="searchbox"><input type="text" size="15" name="searchbox" value=""/>
	    <span class="button"><input type="submit" name="action" value="Search"/></span>
	  </span>
          {% if archive %}
            <span class="count">{{ notes|length }} notes</span>
          {% else %}
            <span class="count">{{ notes|length }} active notes</span>
            <span class="link"><a href="{{ request.path }}?archive=1">View all</a></span>
          {% endif %}
        </div>
        <span class="button"><input type="submit" name="action" value="Download"/></span>
        {% if archive %}
          <span class="button"><input type="submit" name="action" value="Unarchive"/></span>
        {% endif %}
        <span class="button"><input type="submit" name="action" value="Delete" onclick="return confirm('Are you sure you want to permanently delete the selected notes?')"/></span>
      </div>
      <div class="table">
        <table>
          <tr>
            <th class="checkbox"><input type="checkbox" onclick="selectLists(this.checked)"/></th>
            <th>Note Titles</th>
            <th>Notebook</th>
            <th>Last Edited</th>
          </tr>
          </tr>
          {% for note in notes %}
            <tr id="row{{ forloop.counter }}">
              <td class="checkbox"><input class="listcheckbox" type="checkbox" name="note" value="{{ note.key }}" id="checkbox{{ forloop.counter }}" onclick="updateHighlight(this, document.getElementById('row{{ forloop.counter }}'))"/></td>
              <td class="main">
                <div class="name"><a {% if not note.sticky %}class="active"{%endif %} href="/shownote?id={{ note.key|stringformat:"s"|urlencode }}">{{ note.title|escape }}</a></div>
              </td>
              <td class="members">
                none
            
              </td>
              <td class="date">
                {{ note.updated|date:"D, M j, Y \a\t P" }}
              </td>
            </tr>
          {% endfor %}
        </table>
        {% if not notes %}
          <div class="message">You don't have any Notes. To get started, <a href="javascript:newNote()">create a new note</a>.</div>
        {% else %}
          {% if not archive %}
            <div class="message">Showing only recent notes (That's a lie). Looking for something older?  <a href="{{ request.path }}?archive=1">Show all</a></div>
          {% endif %}
        {% endif %}
      </div>
      <div class="buttons bottom">
        <div class="left corner"></div>
        <div class="right corner"></div>
        <span class="button"><input type="submit" name="action" value="Download"/></span>
        {% if archive %}
          <span class="button"><input type="submit" name="action" value="Unarchive"/></span>
        {% endif %}
        <span class="button"><input type="submit" name="action" value="Delete"/></span>
      </div>
    </div>
  </form>

  <div id="newnoteform_dialog" class="dialog" style="display: none">
    <div class="title">New Note</div>
    <div class="content">
      <form action="/createnewnote.do" method="post" id="newnoteform">
        <div class="form">
          <input type="hidden" name="task" value=""/>
          <div class="field">
            <div class="name">Title</div>
            <div class="value"><input name="title" type="text" size="70"/></div>
            <div class="name">Content</div>
            <div class="value"><textarea name="content" rows="4" cols="69"></textarea></div>

          </div>
          <div class="buttons">
            <span class="button"><input type="submit" name="action" value="Create Note"/></span>
            <span class="button"><input type="button" value="Cancel" onclick="DialogBox.instance().close()"/></span>
          </div>
        </div>
      </form>
    </div>
  </div>

{% endblock %}

{% block footer %}
  {% if not debug %}
    <script src="/static/javascript/debug/browser.js" type="text/javascript"></script>
    <script src="/static/javascript/debug/dialog.js" type="text/javascript"></script>
    <script src="/static/javascript/debug/dom.js" type="text/javascript"></script>
    <script src="/static/javascript/debug/drag.js" type="text/javascript"></script>
    <script src="/static/javascript/debug/event.js" type="text/javascript"></script>
    <script src="/static/javascript/debug/io.js" type="text/javascript"></script>
    <script src="/static/javascript/debug/lang.js" type="text/javascript"></script>
    <script src="/static/javascript/debug/offscreen.js" type="text/javascript"></script>
    <script src="/static/javascript/debug/tasklist.js" type="text/javascript"></script>
  {% else %}
    <script src="/static/javascript/tasks.js" type="text/javascript"></script>
  {% endif %}
{% endblock %}
